'''
draw circle 
'''
from  tkinter import *
import math
OX = 400
OY = 400
MAX_X = 800 
MAX_Y = 800 
SCALE_X = 80
SCALE_Y = 80

START = -5.0
END =5.0 
DELTA = 0.01

X_Fix=40
Y_Fix=40

tk = Tk()
canvas = Canvas(tk,width=MAX_X,height=MAX_Y,bd=0)
canvas.pack()

def draw_point (x,y,r =1, c="black"):
    canvas.create_oval(x-r,y+r,x+r,y+r,fill=c,outline=c)

def draw_axes(OX,OY,width,height):
    #use canvas axis
    # (0,500) -> (800,500)
    # draw x axis
    point1 = (0+X_Fix,OY)
    point2 = (width-X_Fix,OY)
    canvas.create_line(point1,point2)
   
    draw_text_fix(point1,"({},{})".format(point1[0],point1[1]),False)
    draw_text_fix(point2,"({},{})".format(point2[0],point2[1]),False)
    # (400,0) -> (400,600)
    # draw y axis
   
    point1= (OX,0+Y_Fix)
    point2 = (OX,height-Y_Fix)
    canvas.create_line(point1,point2)
    draw_text_fix(point1,"({},{})".format(point1[0],point1[1]),False)
    draw_text_fix(point2,"({},{})".format(point2[0],point2[1]),False)

def fx(x):
    return math.cos(x)
def fy(x):
    return math.sin(x)

def plot(x,y):
    # axis convert 
    draw_point(SCALE_X*x+ OX,OY-SCALE_Y*y)
    
    """_summary_
    need_fix：是否使用坐标轴转换
    """
def draw_text_fix(point,text,need_fix=True):
    
    x,y=point
    fix_x=x
    fix_y=y
    fill_color="black"
    if(need_fix):
        fill_color="red"   
        fix_x= SCALE_X*x+ OX
        fix_y=OY-SCALE_Y*y
        
    canvas.create_text(fix_x,fix_y,text=text,fill=fill_color)

draw_axes(OX,OY,MAX_X,MAX_Y)

draw_text_fix((0,0),"(0,0)")

x = START

while x < END:
    #print(x,f(x))
    plot(fx(x),fy(x))
    x = x+ DELTA


tk.mainloop()
    
